package homeworekl;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class Test {
    public static void main(String[] args) {
        Student g1 = new Student("小明",81);
        Student g2 = new Student("小红",100);
        Student g3= new Student("小天",91);

        System.out.println("最大成绩" + max(g1, g2,g3,  new Compare()).getAchievement());

        List<Student> list =new ArrayList<Student>();
        list.add(g1);
        list.add(g2);
        list.add(g3);

        System.out.println("\n升序排序列表元素");
        Collections.sort(list,new Compare());
        for (Student item:list
        ) {

            System.out.println(item.getName()+":"+item.getAchievement());
        }

        System.out.println("\n逆序排序列表元素");
        Collections.reverse(list);
        for (Student item:list
        ) {
            System.out.println(item.getName()+":"+item.getAchievement());

        }

        System.out.println("\n随机序列表元素");
        Collections.shuffle(list);
        for (Student item:list
        ) {
            System.out.println(item.getName()+":"+item.getAchievement());
        }
    }
    public static Student max(Student g1, Student g2,Student g3, Comparator<Student> c) {

        Student result;

        if (c.compare(g1,g2)>0) {
            result = g1;
        }else {
            result=g2;
        }
        if (c.compare(result,g3)>0) {
            return result ;
        }else {
            return result=g3;
        }

        }
}
